function sort(orderBy, defaultOrder) {
	if ($("#orderBy").val() == orderBy) {
		if ($("#order").val() == "") {
			$("#order").val(defaultOrder);
		} else if ($("#order").val() == "desc") {
			$("#order").val("asc");
		} else if ($("#order").val() == "asc") {
			$("#order").val("desc");
		}
	} else {
		$("#orderBy").val(orderBy);
		$("#order").val(defaultOrder);
	}

	$("#mainForm").submit();
}

function search() {
	$("#order").val("");
	$("#orderBy").val("");
	$("#pageNo").val("1");

	$("#mainForm").submit();
}

function sortByColumn(orderBy, order) {
	if (order == "") {
		$("#order").val("asc");
	} else if ($("#order").val() == "desc") {
		$("#order").val("asc");
	} else if ($("#order").val() == "asc") {
		$("#order").val("desc");
	}else{
		$("#order").val("asc");
	}
	
	$("#orderBy").val(orderBy);

	$("#mainForm").submit();
}

/*
 * @auth Jacob, 2010-04-13
 * 
 * for the old version can't handle correctly.
 * this is for bug 1148
 */
function sortByColumn2(orderBy, order) {
	if (order == "") {
		$("#order").val("asc");
	} else if (order == "desc") {
		$("#order").val("asc");
	} else if (order == "asc") {
		$("#order").val("desc");
	}
	$("#orderBy").val(orderBy);
	
	$("#mainForm").submit();
}

function isDigit(s) {
	var patrn = /^[0-9]{1,20}$/;
	if (!patrn.exec(s))
		return false;
	return true;
}

/*
 * @author Liwin.Li
 * 
 * this function compose a form in memory, and it takes two parameters.
 * 
 * action: the URL form want to post
 * fields: the fields included in form. it's formated in "object", looks like "{ 'user':'username', 'password':'12431414', 'new':true, 'number': 1231} "
 */
function SbaPost(action,fields,target){
	//create form, and append it into document
	var form = document.createElement("form");
	form.action = action;
	form.method = "post";
	if( target ) form.target = target;
	document.body.appendChild(form);
	
	//travel the fields, compose every field into form
	for(var f in fields){
		var field = document.createElement("input");
		field.type="hidden";
		field.name=f;
		field.value=fields[f];
		form.appendChild(field);
	}
	
	//submit the form
	form.submit();
}